<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>部门新增</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="${ctx}/assets/plugins/layui/css/layui.css"  media="all">
  <script src="${ctx}/assets/plugins/layui/layui.js"></script>
  <script src="${ctx}/assets/js/app.js"></script>
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
	<form class="layui-form layui-form-pane" action="" style="text-align:center;">
    <div class="layui-inline" style="padding-top:20px;">
      <label class="layui-form-label"><span style='color:red;font-size:15px'>*</span>输入密码</label>
      <div class="layui-input-inline">
        <input type="password" size="24px" id="passwordFir" onblur="validationPaw();" lay-verify="required" placeholder="请输入密码" name="passwordFir" autocomplete="off" class="layui-input">
        <span style="visibility:hidden;color:red;font-size:5px" id="validation">密码不能小于6位</span>
    </div>
  	</div>
  	<div class="layui-inline" style="padding-top:10px;">
      <label class="layui-form-label"><span style='color:red;font-size:15px'>*</span>密码确认</label>
      <div class="layui-input-inline">
        <input type="password" size="24px" lay-verify="required" onblur="validationPawSec();" placeholder="请再次输入密码" id="passwordSec" name="passwordSec" autocomplete="off" class="layui-input">
        <span style="visibility:hidden;color:red;font-size:5px" id="validationSec">两次密码输入不一致</span>
        <input type="hidden" value="${loginUser.pkId}" name="pkId">
    </div>
  	</div>
  	<div class="layui-inline" style="padding-top:20px;">
    <div style="padding-right:80px" class="layui-input-block">
      <button class="layui-btn" lay-submit  lay-filter="btnSubmit">立即提交</button>
    </div>
  </div>
</form>
	<script>
	layui.use(['form'], function() {
        var layer = layui.layer, form = layui.form, $ = layui.$;
        //监听提交
        form.on('submit(btnSubmit)', function(data) {
        	if((document.getElementById("validation").style.visibility=="visible") ||
        			(document.getElementById("validationSec").style.visibility=="visible")){
				return false;
			}
			ajaxExec('${ctx}/sysUser/editPassword', data.field, function(){
				refreshList();
				layer.msg('密码修改成功,页面将在<span style="color:red;">3s</span>后跳转至登录页面！', {
											 icon: 1
											,time: 3000
											,end:function(){
													parent.layer.closeAll();
													ajaxExec('${ctx}/login/logout',null,function(){
														window.location.href = "/login/page";
													})
											}
				});
			}, function(retInfo){
				parent.layer.msg('密码修改失败，' + retInfo.msg, {icon: 2, time: 3500});
			});
            return false;
        });
    	 $('#btnCancle').on('click', function() {
    		parent.layer.closeAll();
    	}); 
    });
    
    function refreshList() {
    	$ = layui.$;
    	parent.layui.$("#btnQuery").click();
    }
    function validationPaw(){
    	$ = layui.$;
    	var passwordFir = $('#passwordFir').val();
    	if(passwordFir.length < 6){
			$('#validation').css("visibility","visible");
    	}
    	if(passwordFir.length >=6){
    		$('#validation').css("visibility","hidden");
    	}
    }
    function validationPawSec(){
    	$ = layui.$;
    	var passwordSec = $('#passwordSec').val();
    	var passwordFir = $('#passwordFir').val();
    	if((document.getElementById("validation").style.visibility == 'hidden')){
			if(passwordSec !== passwordFir){
				$('#validationSec').css("visibility","visible");
			}
			if(passwordSec == passwordFir){
				$('#validationSec').css("visibility","hidden");
			}  		
    	}
    }
	</script>
</body>
</html>